home *** CD-ROM | disk | FTP | other *** search
- /*
- IC Windows.c
-
- */
-
- #include <QuickDraw.h>
- #include <ToolUtils.h>
-
- #include "IC Globals.h"
- #include "IC Window Globals.h"
- #include "IC Misc Subs.h"
- #include "IC Types.h"
- #include "IC API.h"
- #include "IC Dialogs.h"
- #include "IC Text.h"
- #include "IC Globals.h"
- #include "IC Keys.h"
- #include "IC Text Whats.h"
- #include "IC Popup Whats.h"
- #include "IC Font Whats.h"
- #include "IC FSSpec Whats.h"
- #include "IC File Map What.h"
- #include "IC Helper What.h"
- #include "IC Button What.h"
- #include "IC Document.h"
- #include "IC Windows.h"
- #include "IC Subs.h"
- #include "IC CheckBox What.h"
- #include "IC Events.h"
-
- #include "SpinLib.h"
-
- /*
- Force the update of the about window.
- */
- void InvalidateAbout(void){
- Rect r;
- WindowPeek peek=(WindowPeek)(WindowInfo[WT_About].window);
- GrafPtr cur;
-
- if (peek->visible){
- // get the rect of our little item
- GetPort(&cur);
- SetPort(WindowInfo[WT_About].window);
-
- GetDItemRect(WindowInfo[WT_About].window,8,&r);
-
- // invalidate it so we get a redraw.
- InvalRect(&r);
-
- SetPort(cur);
- }
- }
-
- OSErr CallWhatOpen(WindowType wt,short item,WindowPlainUPP open){
- return CallWindowPlainProc(open,wt,item);
- }
-
- OSErr CallWhatClose(WindowType wt,short item,WindowPlainUPP close){
- return CallWindowPlainProc(close,wt,item);
- }
-
- OSErr CallWhatFlush(WindowType wt,short item,WindowPlainUPP flush){
- return CallWindowPlainProc(flush,wt,item);
- }
-
- OSErr CallWhatClick(WindowType wt,short item,EventRecord* er,WindowEventUPP click){
- return CallWindowEventProc(click,wt,item,er);
- }
-
- OSErr CallWhatKey(WindowType wt,short item,EventRecord* er,WindowEventUPP key){
- return CallWindowEventProc(key,wt,item,er);
- }
-
- OSErr CallWhatActivate(WindowType wt,short item,Boolean activate,WindowBooleanUPP actproc){
- return CallWindowBooleanProc(actproc,wt,item,activate);
- }
-
- OSErr CallWhatIdle(WindowType wt,short item,WindowPlainUPP idleproc){
- return CallWindowPlainProc(idleproc,wt,item);
- }
-
- OSErr CallWhatCursor(WindowType wt,short item,Point pt,short curs,WindowCursorUPP cursproc){
- return CallWindowCursorProc(cursproc,wt,item,pt,curs);
- }
-
- short TypeToWhat(OSType typ){
- short i;
-
- for (i=1;i<=whats_max;i++){
- if (WhatInfo[i].typ==typ){
- return i;
- }
- }
-
- return 1;
- }
-
- OSType GetWhatType(WindowType wt,short item){
- WhatRecordPtr wrp;
-
- if (item>item_max)
- return (OSType)0;
-
- wrp=WindowInfo[wt].items[item];
- if (wrp==(WhatRecordPtr)0)
- return 'NULL';
-
- return wrp->typ;
- }
-
- WindowPtr GetWindowPtr(WindowType wt){
- return WindowInfo[wt].window;
- }
-
- Boolean OurWindow(WindowPtr wp){
- return GetWindowType(wp)!=WT_None;
- }
-
- OSErr WhatIdleText(WindowType wt,short item,short* cursor){
- Rect r;
- Point pt;
-
- GetDItemRect(WindowInfo[wt].window,item,&r);
- GetMouse(&pt);
- if (PtInRect(pt,&r))
- *cursor=iBeamCursor;
- return noErr;
- }
-
- void DoWindowIdle(WindowPtr window){
- short i,selected_item,cursorid;
- WhatRecordPtr what;
- WindowType wt;
- Rect r;Point pt;
- WindowCursorUPP cursor;
- Boolean cursor_set;
-
- SetPort(window);
- wt=GetWindowType(window);
- selected_item=GetSelectedItem(wt);
- if (selected_item>0)
- TextIdle(WindowInfo[wt].items[selected_item]->data);
-
- if ((window==FrontWindow())&&(InForeground())){
- GetMouse(&pt);
- cursor_set=false;
-
- for (i=1;i<=item_max;i++){
- what=WindowInfo[wt].items[i];
- if (what!=(WhatRecordPtr)0){
- GetDItemRect(window,i,&r);
- if (PtInRect(pt,&r)){
- cursor_set=true;
- cursorid=WhatInfo[TypeToWhat(what->typ)].cursorid;
- cursor=(WindowCursorUPP)WhatInfo[TypeToWhat(what->typ)].cursor;
-
- if (cursor==(WindowCursorUPP)0){
- if (cursorid==0)
- InitCursor();
- else {
- CursHandle curs;
-
- curs=GetCursor(cursorid);
- if (curs!=(CursHandle)0)
- SetCursor(*curs);
- }
- } else
- CallWhatCursor(wt,i,pt,cursorid,cursor);
- }
- }
- }
-
- if (!cursor_set)
- InitCursor();
- }
- }
-
- void WindowDoKey(WindowPtr window,EventRecord* er){
- short wt=GetWindowType(window);
- short selected_item=WindowInfo[wt].selected_item;
- WindowEventUPP key;
-
- if (selected_item>0){
- key=(WindowEventUPP)WhatInfo[TypeToWhat(GetWhatType(wt,selected_item))].key;
- if (key!=(WindowEventUPP)0){
- SetPort(window);
- DisplayError(acDoThis,CallWhatKey(wt,selected_item,er,key));
- }
- }
- }
-
- void WindowActivateDeactivate(WindowPtr window,Boolean activate){
- WindowType wt=GetWindowType(window);
- short item,i;
- WindowBooleanUPP actproc;
- WhatRecordPtr what;
- OSErr err;
-
- if (wt!=WT_None){
- SetPort(window);
- item=GetSelectedItem(wt);
- if (item>0)
- TextActivate(WindowInfo[wt].items[item]->data,activate);
- for (i=1;i<=item_max;i++){
- what=WindowInfo[wt].items[i];
- if (what!=(WhatRecordPtr)0){
- actproc=(WindowBooleanUPP)WhatInfo[TypeToWhat(what->typ)].activate;
- if (actproc!=(WindowBooleanUPP)0){
- err=CallWhatActivate(wt,i,activate,actproc);
- if ((err!=noErr)&&(err!=userCanceledErr))
- SysBeep(1);
- }
- }
- }
- }
- }
-
- ICError LaunchSomeSillyURL(StringPtr url){
- long start,fin;
- Str255 hint="\p";
-
- start=url[0]/2;
- fin=start;
-
- return ICLaunchURL(GetInstance(),hint,(Ptr)&(url[1]),url[0],&start,&fin);
- }
-
- void DoAboutClick(WindowPtr window,short item){
- short a;
- Str255 s;
-
- if (TrackItems(window,item,0,0)){
- if (item==6){
- a=NoteAlert(167,gCancelModalFilter);
- if (a==1)
- item=7;
- else if (a==2)
- item=0;
- }
-
- if (item==8) // no url for the latest item
- item=0;
-
- if (item!=0){
- GetIndString(s,129,item);
- DisplayError(acDoThis,LaunchSomeSillyURL(s));
- }
- }
- }
-
- void WindowItemWhere(WindowPtr window,EventRecord* er,short item){
- WindowEventUPP click;
- WindowType wt=GetWindowType(window);
-
- if (wt==WT_About)
- DoAboutClick(window,item);
- else {
- click=(WindowEventUPP)WhatInfo[TypeToWhat(GetWhatType(wt,item))].click;
- if (click!=(WindowEventUPP)0){
- SetPort(window);
- DisplayError(acDoThis,CallWhatClick(wt,item,er,click));
- }
- }
- }
-
- Boolean WindowEarlyHandleEvent(WindowPtr window,EventRecord* er){
- return false;
- }
-
- void WindowTab(WindowPtr window,Boolean shift){
- short orgitem,rorgitem,i,dirn,selitem=-1;
- OSType t;
- WindowType wt=GetWindowType(window);
- short ash=(shift)?2:0;
-
- orgitem=rorgitem=GetSelectedItem(wt);
- if (orgitem<=0){
- if (shift)
- orgitem=1;
- else
- orgitem=item_max;
- }
- dirn=item_max-ash;
- i=orgitem;
-
- do {
- i=(i+dirn)%item_max +1;
- t=GetWhatType(wt,i);
- if (t=='TEXT'){
- selitem=i;
- break;
- }
- } while (i!=orgitem);
- if (selitem>0)
- SelectTextItem(wt,selitem);
- }
-
- Boolean WindowEarlyHandleKey(WindowPtr window,EventRecord* er){
- Boolean b=false;
- char ch;
- WindowType wt=GetWindowType(window);
-
- if (!WindowInfo[wt].window_key_needs_tabs){
- ch=er->message&0xff;
- if (ch==tabChar){
- WindowTab(window,((er->modifiers&shiftKey)!=0));
- b=true;
- }
- }
- return b;
- }
-
- OSErr FlushWindowType(WindowPtr wp,WindowType wt){
- short i;
- OSErr first_err=noErr,err;
- WindowPlainUPP flush;
- WhatRecordPtr what;
- Rect portrect;
-
- SetPort(wp);
- GetWindowRect(wp,&portrect);
- WindowInfo[wt].position=topLeft(portrect);
- for (i=1;i<=item_max;i++){
- what=WindowInfo[wt].items[i];
- if (what!=(WhatRecordPtr)0){
- flush=(WindowPlainUPP)WhatInfo[TypeToWhat(what->typ)].flush;
- if (flush!=(WindowPlainUPP)0){
- err=CallWhatFlush(wt,i,flush);
- if (first_err==noErr)
- first_err=err;
- }
- }
- }
-
- return first_err;
- }
-
- OSErr DisposeWindowType(WindowPtr wp,WindowType wt){
- short i;
- OSErr err,first_err=noErr;
- WindowPlainUPP close;
- WhatRecordPtr what;
-
- SetPort(wp);
- for (i=1;i<=item_max;i++){
- what=WindowInfo[wt].items[i];
- if (what!=(WhatRecordPtr)0){
- close=(WindowPlainUPP)WhatInfo[TypeToWhat(what->typ)].close;
- if (close!=(WindowPlainUPP)0){
- err=CallWhatClose(wt,i,close);
- if (first_err==noErr)
- first_err=err;
- }
- WindowInfo[wt].items[i]=(WhatRecordPtr)0;
- DisposePtr((Ptr)what);
- }
- }
-
- WindowInfo[wt].window=(DialogPtr)0;
- DisposeDialog(wp);
- return first_err;
- }
-
- OSErr CloseWindowType(WindowPtr wp,WindowType wt){
- OSErr err,err2;
- Boolean opened=false;
-
- err=ICMapErr(ICBegin(GetInstance(),icReadWritePerm));
- if (err==noErr){
- opened=true;
- err=FlushWindowType(wp,wt);
- }
-
- err2=DisposeWindowType(wp,wt);
-
- if (err==noErr)
- err=err2;
-
- if (opened){
- err2=ICMapErr(ICEnd(GetInstance()));
- if (err==noErr)
- err=err2;
- }
-
- InvalidateAbout();
-
- return err;
- }
-
- Boolean WindowsEarlyHandleEvent(EventRecord* er){
- WindowPtr wp=FrontWindow();
-
- if (GetWindowType(wp)!=WT_None)
- return WindowEarlyHandleEvent(wp,er);
- return false;
- }
-
- Boolean WindowsEarlyHandleKey(EventRecord* er){
- WindowPtr wp=FrontWindow();
-
- if (GetWindowType(wp)!=WT_None)
- return WindowEarlyHandleKey(wp,er);
- return false;
- }
-
- void WindowsDoKey(EventRecord* er){
- WindowPtr wp=FrontWindow();
-
- if (GetWindowType(wp)!=WT_None)
- WindowDoKey(wp,er);
- }
-
- void WindowsIdle(void){
- WindowType wt;
-
- for (wt=WT_None;wt<=WT_Last;wt++){
- if (WindowInfo[wt].window!=(WindowPtr)0)
- DoWindowIdle(WindowInfo[wt].window);
- }
- }
-
- void WindowsSetTitle(WindowType wt,const StringPtr title){
- if (WindowInfo[wt].window!=(WindowPtr)0)
- SetWTitle(WindowInfo[wt].window,title);
- }
-
- void WindowsAdjustMenus(void){
- AdjustTextMenu(GetWindowType(FrontWindow()));
- }
-
- void WindowsDoEditMenu(short item){
- WindowPtr wp=FrontWindow();
- WindowType wt=GetWindowType(wp);
-
- if (wt!=WT_None)
- DoTextMenu(wt,item);
- }
-
- short GetWindowID(WindowType wt){
- if (wt==WT_About)
- return 128;
-
- return 200+wt-WT_Main;
- }
-
- Boolean IsPrefix(StringPtr s,const StringPtr key){
- Str255 ts;
-
- if (IUEqualString(TPCopy(ts,s,1,key[0]),key)==0){
- TPCopy(ts,s,key[0]+1,255);
- SetPString(s,1,ts);
- return true;
- }
- return false;
- }
-
- OSErr EditCurrentPreference(StringPtr key){
- WindowType wt;
- WhatTemplateArrayHandle what;
- OSErr err=(OSErr)-1;
- short i,id;
- Str255 map;
-
- if (IsPrefix(key,SetPString(map,2,kICMapping,"\p•"))){
- err=WindowsOpen(WT_FileMapping);
- if (err==noErr)
- MappingSetSelection(key);
- } else if (IsPrefix(key,kICHelper)){
- err=WindowsOpen(WT_Helper);
- if (err==noErr)
- HelperSetSelection(key);
- } else {
- for (wt=WT_None;wt<=WT_Last;wt++){
- id=GetWindowID(wt);
- what=(WhatTemplateArrayHandle)GetResource('WHAT',id);
- if (what!=(WhatTemplateArrayHandle)0){
- HLock((Handle)what);
- for (i=1;i<=(GetHandleSize((Handle)what)/sizeof(WhatTemplateRecord));i++){
- if (IUEqualString(key,(*what)[i].key)==0){
- err=WindowsOpen(wt);
- if ((*what)[i].typ=='TEXT')
- SelectTextItem(wt,i);
- }
- }
- HUnlock((Handle)what);
- ReleaseResource((Handle)what);
- }
- }
- }
- return err;
- }
-
- OSErr PrepWindow(WindowType wt,short id,WindowPtr wp){
- short i,what;
- OSErr err,first_err=noErr;
-
- SetPort(wp);
-
- WindowInfo[wt].window=wp;
- WindowInfo[wt].id=id;
- WindowInfo[wt].selected_item=-1;
- WindowInfo[wt].window_key_needs_tabs=true;
- first_err=ParseWhat(wt);
- if (first_err==noErr){
- for (i=1;i<=item_max;i++){
- if (WindowInfo[wt].items[i]!=(WhatRecordPtr)0){
- if (WindowInfo[wt].items[i]->typ=='TEXT')
- WindowInfo[wt].window_key_needs_tabs=false;
- what=TypeToWhat(WindowInfo[wt].items[i]->typ);
- if (((WindowPlainUPP)WhatInfo[what].open)!=(WindowPlainUPP)0){
- err=CallWhatOpen(wt,i,(WindowPlainUPP)WhatInfo[what].open);
- if (first_err==noErr)
- first_err=err;
- }
- }
- }
- }
-
- if (first_err==noErr)
- if (WindowInfo[wt].selected_item==-1)
- WindowTab(WindowInfo[wt].window,false);
-
- return first_err;
- }
-
- OSErr ParseWhat(WindowType wt){
- WhatTemplateArrayHandle what;
- short i,max;
- OSErr err=noErr;
- long size;
-
- for (i=1;i<=item_max;i++)
- WindowInfo[wt].items[i]=(WhatRecordPtr)0;
-
- what=(WhatTemplateArrayHandle)GetResource('WHAT',WindowInfo[wt].id);
- if (what!=(WhatTemplateArrayHandle)0){
- HLock((Handle)what);
-
- size=GetHandleSize((Handle)what);
- max=(size)/sizeof(WhatTemplateRecord);
-
- for (i=0;i<max;i++){
- if ((*what)[i].typ!='NULL'){
- WindowInfo[wt].items[i+1]=(WhatRecordPtr)NewPtr(sizeof(WhatRecord));
- err=MemError();
- if (err!=noErr)
- break;
- SetPString(WindowInfo[wt].items[i+1]->key,1,(*what)[i].key);
- WindowInfo[wt].items[i+1]->typ=(*what)[i].typ;
- WindowInfo[wt].items[i+1]->flags=(*what)[i].flags;
- } else {
- // must clear the record ptr...
- WindowInfo[wt].items[i+1]=(WhatRecordPtr)0;
- }
- if (err!=noErr)
- break; // just in case
- }
- HUnlock((Handle)what);
- ReleaseResource((Handle)what);
- }
- return err;
- }
-
- OSErr NewICWindow(WindowType wt){
- DialogPtr wp=(DialogPtr)0;
- Point position;
- Rect original_position;
- OSErr err,err2;
- short id=GetWindowID(wt),dlg_id;
-
- err=ICMapErr(ICBegin(GetInstance(),icReadWritePerm));
- if (err==noErr){
- dlg_id=id;
- if ((wt==WT_Font)&&(!System7))
- dlg_id=290;
- wp=GetNewDialog(dlg_id,(Ptr)0,(WindowPtr)-1);
- if (wp==(DialogPtr)0)
- err=memFullErr;
- if (err==noErr)
- err=PrepWindow(wt,id,wp);
- if (err==noErr){
- position=WindowInfo[wt].position;
- if ((position.h!=0)||(position.v!=0)){
- GetWindowRect(wp,&original_position);
- MoveWindow(wp,position.h,position.v,false);
- ShowWindow(wp); // because TitleBarOnScreen required window to be shown
- if (!TitleBarOnScreen(wp))
- MoveWindow(wp,original_position.left,original_position.top,false);
- }
- ShowWindow(wp);
- }
- err2=ICMapErr(ICEnd(GetInstance()));
- if (err==noErr)
- err=err2;
- }
-
- // tidy up code
-
- if (err!=noErr)
- if (wp!=(DialogPtr)0)
- DisposeWindowType(wp,wt);
-
- return err;
- }
-
- OSErr WindowsOpen(WindowType wt){
- OSErr err;
-
- if (WindowInfo[wt].window!=(WindowPtr)0){
- ShowWindow(WindowInfo[wt].window);
- SelectWindow(WindowInfo[wt].window);
-
- return noErr;
- }
-
- /*
- A little glue to spin the cursor when we open a window. This usually isn't necessary, but
- when opening the font window the building of the font menus can take some time to fill if there
- are a lot of fonts to add to the menu. This will ensure that the user knows that we are doing
- something and not really hung (which is what I thought the first time I opened the font window
- and had to wait and wait and wait for it to build the menus).
- */
- SpinStart(kForwardDirection);
-
- // also purge & compact memory
- PrepMem();
-
- err=NewICWindow(wt);
-
- InvalidateAbout();
-
- SpinStop();
-
- return err;
- }
-
- OSErr WindowsClose(WindowPtr wp){
- WindowType wt=GetWindowType(wp);
-
- if (wt!=WT_None)
- return CloseWindowType(wp,wt);
-
- return noErr;
- }
-
- void WindowsResetPositions(void){
- WindowType wt;
- Point pos;
-
- pos.h=2;
- pos.v=42;
-
- for (wt=WT_Main;wt<WT_Last;wt++){
- WindowInfo[wt-WT_Main].position=pos;
- pos.h+=20*(qd.screenBits.bounds.right>512);
- pos.v+=10*(qd.screenBits.bounds.bottom>=400)+8*(qd.screenBits.bounds.bottom>=480);
- }
- }
-
- void WindowsRestorePositions(void){
- OSErr err,err2;
- long attr;
- PointArray window_positions=(PointArray)NewPtr(sizeof(Point)*WT_Last);
- long size;
- WindowType wt;
-
- err=ICMapErr(ICBegin(GetInstance(),icReadOnlyPerm));
- if (err==noErr){
- size=sizeof(Point)*WT_Last;
- err=ICMapErr(ICGetPref(GetInstance(),OurWindowPositionKey,&attr,(Ptr)window_positions,&size));
- if ((err==noErr)&&(size!=(sizeof(Point)*WT_Last)))
- err=(OSErr)-1;
- err2=ICMapErr(ICEnd(GetInstance()));
- if (err==noErr)
- err=err2;
- }
-
- if (err==noErr){
- for (wt=WT_Main;wt<WT_Last;wt++)
- WindowInfo[wt].position=window_positions[wt-WT_Main];
- } else
- WindowsResetPositions();
-
- DisposePtr((Ptr)window_positions);
- }
-
- void WindowsSavePositions(void){
- OSErr err,err2;
- WindowType wt;
- PointArray windows_positions=(PointArray)NewPtr(sizeof(Point)*WT_Last);
-
- for (wt=WT_Main;wt<WT_Last;wt++)
- windows_positions[wt-WT_Main]=WindowInfo[wt].position;
-
- err=ICMapErr(ICBegin(GetInstance(),icReadWritePerm));
- if (err==noErr){
- err=ICMapErr(ICSetPref(GetInstance(),OurWindowPositionKey,ICattr_no_change,(Ptr)windows_positions,(sizeof(Point)*WT_Last)));
- ICMapErr(ICEnd(GetInstance()));
- }
- DisposePtr((Ptr)windows_positions);
- }
-
- OSErr WindowsFlushAll(void){ // flush all information windows
- WindowType wt;
- OSErr first_err,err;
-
- first_err=ICMapErr(ICBegin(GetInstance(),icReadWritePerm));
- if (first_err==noErr){
- for (wt=WT_Main;wt<=WT_Last;wt++){
- if (WindowInfo[wt].window!=(WindowPtr)0){
- SetPort(WindowInfo[wt].window);
- err=FlushWindowType(WindowInfo[wt].window,wt);
- if (first_err==noErr)
- first_err=err;
- }
- }
- err=ICMapErr(ICEnd(GetInstance()));
- if (first_err==noErr)
- first_err=err;
- }
-
- return first_err;
- }
-
- OSErr WindowsCloseAll(void){ // close all information windows
- WindowType wt;
- OSErr err,first_err=noErr;
-
- for (wt=WT_Personal;wt<=WT_Last;wt++){
- if (WindowInfo[wt].window!=(WindowPtr)0){
- err=CloseWindowType(WindowInfo[wt].window,wt);
- if (first_err==noErr)
- first_err=err;
- }
- }
-
- return first_err;
- }
-
- void W(short what,OSType xtyp,WindowPlainUPP xopen,WindowEventUPP xkey,WindowEventUPP xclick,
- WindowPlainUPP xidle,WindowPlainUPP xflush,WindowPlainUPP xclose,WindowBooleanUPP xactivate,
- WindowCursorUPP xcursor,short xcursorid){
- WhatInfo[what].typ=xtyp;
- WhatInfo[what].open=xopen;
- WhatInfo[what].key=xkey;
- WhatInfo[what].click=xclick;
- WhatInfo[what].flush=xflush;
- WhatInfo[what].close=xclose;
- WhatInfo[what].activate=xactivate;
- WhatInfo[what].idle=xidle;
- WhatInfo[what].cursor=xcursor;
- WhatInfo[what].cursorid=xcursorid;
- }
-
- void InitWhats(void){
- WindowPlainUPP np=(WindowPlainUPP)0;
- WindowEventUPP ne=(WindowEventUPP)0;
- WindowBooleanUPP nb=(WindowBooleanUPP)0;
- WindowCursorUPP nc=(WindowCursorUPP)0;
-
- // quick definitions to shorten the function calls
- #define NPP NewWindowPlainProc
- #define NBP NewWindowBooleanProc
- #define NEP NewWindowEventProc
- #define NCP NewWindowCursorProc
-
- W(whatNULL,'NULL',np,ne,ne,np,np,np,nb,nc,0);
-
- W(whatTEXT,'TEXT',NPP(WhatOpenText),NEP(WhatKeyText),NEP(WhatClickText),np,NPP(WhatFlushText),NPP(WhatCloseText),
- nb,nc,iBeamCursor);
-
- W(whatSPOP,'SPOP',NPP(WhatOpenPopup),ne,NEP(WhatClickPopup),np,NPP(WhatFlushPopup),NPP(WhatClosePopup),nb,nc,0);
-
- W(whatFFSP,'FFSP',NPP(WhatOpenFSSpec),ne,NEP(WhatClickFSSpec),np,NPP(WhatFlushFSSpec),np,nb,nc,0);
-
- W(whatFPOP,'FPOP',NPP(WhatOpenFont),ne,NEP(WhatClickFont),np,NPP(WhatFlushFont),np,nb,nc,0);
-
- W(whatFMAP,'FMAP',NPP(WhatOpenFileMap),NEP(WhatKeyFileMap),NEP(WhatClickFileMap),np,NPP(WhatFlushFileMap),NPP(WhatCloseFileMap),
- NBP(WhatActivateFileMap),
- NCP(WhatCursorFileMap),
- plusCursor);
-
- W(whatFBUT,'FBUT',np,ne,NEP(WhatClickFileMap),np,np,np,nb,nc,0);
-
- W(whatHMAP,'HMAP',NPP(WhatOpenHelper),NEP(WhatKeyHelper),NEP(WhatClickHelper),np,NPP(WhatFlushHelper),NPP(WhatCloseHelper),
- NBP(WhatActivateHelper),NCP(WhatCursorHelper),plusCursor);
-
- W(whatHBUT,'HBUT',np,ne,NEP(WhatClickHelper),np,np,np,nb,nc,0);
-
- W(whatBUTN,'BUTN',NPP(WhatOpenButton),ne,NEP(WhatClickButton),np,np,np,nb,nc,0);
-
- W(whatFSIZ,'FSIZ',np,ne,NEP(WhatClickFontSize),np,np,np,nb,nc,0);
-
- W(whatCBOX,'CBOX',NPP(WhatOpenCheckBox),ne,NEP(WhatClickCheckBox),np,NPP(WhatFlushCheckBox),np,
- nb,nc,0);
- }
-
- pascal void AboutBoxUpdate(DialogPtr dlg,short item){
- Rect r;
- Str255 st,ds;
-
- GetDItemRect(dlg,item,&r);
-
- switch (item){
- case 1:
- DrawIcon(128,&r,false);
- break;
- case 3:
- DisplayStyledString(dlg,item,SetPString(st,2,GetAString(st,129,item),app_version.shortVersion));
- break;
- case 8:
- /*
- DHN- I added this item to the about window to describe the current settings of the application,
- such as the current version of the installed component, the component in the app that can be
- installed, and whether the linked-in glue was being used or not. It will also display the full
- path to the prefs file in use, even memory availability and other things. Perhaps even my own
- styled string may be put in here... ;-)
- */
- {
- SavedWindowInfo sav;
- Str255 str,s1;
- extern long application_version,installed_version;
- long tot,pur;
- extern OSErr FSSpecToFullPath(FSSpecPtr fs,StringPtr path);
- extern FSSpec current_file;
- FSSpec copy;
-
- EnterWindow(dlg,geneva,9,0,&sav);
-
- // draw a separator line
- MoveTo(r.left,r.top+1);
- LineTo(r.right,r.top+1);
-
- MoveTo(r.left+4,r.top+11);
- SetPString(str,2,"\pApplication Component Version: ",VersionStr(application_version,s1));
- DrawString(str);
-
- MoveTo(r.left+4,r.top+21);
- SetPString(str,2,"\pInstalled Component Version: ",VersionStr(installed_version,s1));
- DrawString(str);
-
- MoveTo(r.left+4,r.top+31);
- if (!ICComponentEnabled())
- SetPString(s1,1,"\pDisabled");
- else
- SetPString(s1,1,"\pEnabled");
-
- SetPString(str,2,"\pComponent is ",s1);
- DrawString(str);
-
- MoveTo(r.left+4,r.top+41);
-
- // make a copy of the fsspec because
- BlockMoveData((Ptr)(¤t_file),(Ptr)(©),sizeof(FSSpec));
- // FSSpecToFullPath modifies the spec
- FSSpecToFullPath(©,s1);
- SetPString(str,2,"\pPref File: ",s1);
-
- // str is the full string, but we need to split it onto two lines...
- if (StringWidth(str)>(r.right-r.left)-8){
- // it is greater, try to split into two...
- unsigned char c=str[0];
- Boolean done=false;
-
- while (!done){
- while ((str[c]!=' ')&&(str[c]!='-')&&(str[c]!=':'))
- c--;
-
- TPCopy(s1,str,1,c);
-
- done=(StringWidth(s1)<=((r.right-r.left)-8));
- if (!done)
- c--;
- }
-
- // chars 1 through c are now stored in s1, and s1 can be printed
- DrawString(s1);
-
- MoveTo(r.left+8,r.top+51);
- // chars 1 through c should be deleted from str, then it can be printed
- DrawString(Delete(str,1,c));
- } else {
- // finish off with the last piece...
- DrawString(str);
- }
-
- r.left+=4;
- r.top+=53;
- EraseRect(&r);
-
- MoveTo(r.left,r.top+8);
- PurgeSpace(&tot,&pur);
- tot/=1024;
- SetPString(str,3,"\pApproximately ",DecStr(tot,s1),"\p KB available");
- DrawString(str);
-
- ExitWindow(&sav);
- }
- break;
- default:
- DisplayStyledString(dlg,item,GetAString(st,129,item));
- break;
- }
- }
-
- UserItemUPP __gAboutBoxUpdate;
-
- OSErr InitICWindows(void){
- WindowType wt;
- short i,kind;
- WindowPtr wp;
- OSErr err;
-
- InitICWindowGlobals();
- InitWhats();
-
- // Initialize the spinning cursor library
- err=SpinInit();
-
- for (wt=WT_None;wt<=WT_Last;wt++){
- WindowInfo[wt].window=(DialogPtr)0;
- WindowInfo[wt].window_key_needs_tabs=false;
- WindowInfo[wt].position.h=WindowInfo[wt].position.v=0;
- }
-
- WindowsResetPositions();
-
- // bring the about box up hidden and leave it there
-
- err=noErr;
- wp=GetNewDialog(128,(Ptr)0,(WindowPtr)-1);
- WindowInfo[WT_About].window=wp;
- if (wp==(WindowPtr)0)
- err=memFullErr;
-
- if (err==noErr)
- err=PrepWindow(WT_About,128,wp);
-
- if (err==noErr){
- short cnt=CountDItems(wp);
- __gAboutBoxUpdate=NewUserItemProc(AboutBoxUpdate);
-
- for (i=1;i<=cnt;i++){
- GetDItemKind(wp,i,&kind);
-
- if ((kind&0x007f)==userItem)
- SetDItemHandle(wp,i,(Handle)__gAboutBoxUpdate);
- }
- }
-
- return err;
- }
-
-